﻿
(function() {
    'use strict';
    var app = angular.module('app', ['ngRoute', 'ui.bootstrap']);

    app.config(function($routeProvider, $locationProvider) {
        $routeProvider
            .when('/joesweb', {
                controller: 'MainController',
                templateUrl: '/app/main/main.html',
                action: 'joes web'
            })
            .when('/joesweb/resume', {
                controller: 'ResumeController',
                templateUrl: '/app/resume/resume.html',
                action: 'resume'
            })
            .when('/joesweb/carousel', {
                controller: 'CarouselController',
                templateUrl: '/app/carousel/carousel.html',
                action: 'riding along on a carousel'
            })
            .when('/joesweb/resume/:id', {
                controller: 'ResumeController',
                templateUrl: '/app/resume/resume.html',
                action: 'resuming my resume'
            })
            .when('/joesweb/skillTypes', {
                controller: 'SkillTypeController',
                templateUrl: '/app/admin/resume/skillType/skillTypes.html',
                action: 'admin skill types',
                resolve: {
                    skillTypesInit: function(skillTypeFactory) {
                        return skillTypeFactory.getSkillTypes();
                    }
                }
            })
            .when('/joesweb/skills', {
                controller: 'SkillsController',
                templateUrl: '/app/admin/resume/skill/skills.html',
                action: 'admin skill types',
                resolve: {
                    skillTypesInit: function(skillTypeFactory) {
                        return skillTypeFactory.getSkillTypes();
                    }
                }
            })
            .when('/joesweb/skillType/add', {
                controller: 'SkillTypeEditController',
                templateUrl: '/app/admin/resume/skillType/skillTypeAdd.html',
                action: 'admin skill types add new'
            })
            .when('/joesweb/skills/:id', {
                controller: 'SkillsController',
                templateUrl: '/app/admin/resume/skill/skills.html',
                action: 'admin skill types',
                resolve: {
                    skillTypeSkills: function(skillsInitialResolverFactory, $route) {
                        return skillsInitialResolverFactory($route.current.params.id);
                    }
                }
            })
            .when('/joesweb/educations', {
                controller: 'EducationsController',
                templateUrl: '/app/admin/resume/education/educations.html',
                action: 'educations',
                resolve: {
                    educationsInit: function(educationsFactory) {
                        return educationsFactory.getEducations();
                    }
                }

            })
            .otherwise({ redirectTo: '/joesweb' });
        $locationProvider.html5Mode(true);
    });

    app.run([
        '$rootScope', '$location',
        function($rootScope, $location) {
            //Client-side security. Server-side framework MUST add it's 
            //own security as well since client-based security is easily hacked
            $rootScope.$on("$routeChangeStart", function(event, next, current) {
                $rootScope.isLoading = true;
                console.log("$routeChangeStart");
                //console.log({ "event": event });
                //console.log({ "next": next });
                //console.log({"location": $location });
                //console.log({"current": current });
            });
            
            $rootScope.$on("$routeChangeSuccess", function (event, current) {
                $rootScope.isLoading = false;
                console.log("$routeChangeSuccess");
                //console.log({ "event": event });
                //console.log({ "current": current });
                //console.log({ "location": $location });
            });

            $rootScope.$on("$routeChangeError", function (event, current) {
                $rootScope.isLoading = false;
                //console.log("$routeChangeError");
                console.log({ "event": event });
                //console.log({ "current": current });
                //console.log({ "location": $location });
            });
        }
    ]);
}());